package zkk.com.mengqu.fragment;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import zkk.com.mengqu.R;
import zkk.com.mengqu.activity.AddressActivity;
import zkk.com.mengqu.activity.LoginCodeActivity;
import zkk.com.mengqu.activity.UserDetailActivity;
import zkk.com.mengqu.simplepreferences.Share;
import zkk.com.mengqu.util.FinalString;

public class UserFragment extends Fragment implements View.OnClickListener{
    private  View view;
    private Context context;
    private RelativeLayout rlLogin;
    private LinearLayout address;
    private TextView userName;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_my,container,false);
        context = getActivity();
        initView();
        return view;
    }

    public void initView(){
        rlLogin = (RelativeLayout)view.findViewById(R.id.rl_login);
        userName = (TextView)view.findViewById(R.id.tx_user_name);
        address = (LinearLayout) view.findViewById(R.id.ll_my_address);

        rlLogin.setOnClickListener(this);
        address.setOnClickListener(this);
    }

    @Override
    public void onResume() {
        super.onResume();
        Log.w("UserName","" + "null".equals(Share.getUserPhone()));
        if (!"null".equals(Share.getUserPhone())){
            userName.setText(Share.getUserPhone());
        }else {
            userName.setText(R.string.my_no_login);
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.rl_login:
                if (!"null".equals(Share.getUserPhone())){
                    startActivity(new Intent(getActivity() , UserDetailActivity.class));
                }else {
                    startActivity(new Intent(getActivity() , LoginCodeActivity.class));
                }

                break;
            case R.id.ll_my_address:

                if (!"null".equals(Share.getUserPhone())){
                    Intent intent = new Intent(getActivity(), AddressActivity.class);
                    intent.putExtra(FinalString.ADDRESS_TYPE, FinalString.SHOW_ADDRESS);
                    startActivity(intent);
                }else {
                    startActivity(new Intent(getActivity() , LoginCodeActivity.class));
                }

                break;
            default:
                break;
        }
    }
}
